﻿using DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataEntity;

namespace WebUI.Controllers
{
    public class CompanyConfigController : Controller
    {
        //
        // GET: /CompanyConfig/
        private DataContext db = new DataContext();
        /// <summary>
        /// 菜单
        /// </summary>
        /// <returns></returns>
        private IEntityRepository<SysCompanyConfig> CompanyConfigRepository;
        public CompanyConfigController()
        {
            CompanyConfigRepository = new EntityRepository<SysCompanyConfig>(db);
        }
        public ActionResult Index()
        {
            var model = CompanyConfigRepository.Get().FirstOrDefault();
            return View(model);
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="menumodel"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Save(SysCompanyConfig model)
        {
            try
            {
                
                if (model.ID == 0)
                {
                    CompanyConfigRepository.Insert(model);
            
                }
                else
                {
                    var companyConfig = CompanyConfigRepository.GetByKey(model.ID);
                    companyConfig.CompanyName = model.CompanyName;
                    companyConfig.Address = model.Address;
                    companyConfig.Summary = model.Summary;
                    companyConfig.CompanyLogo = model.CompanyLogo;
                    CompanyConfigRepository.Update(companyConfig);

                }
                return Json(new { success = true });


            }
            catch (Exception e)
            {
                return Json(new { msg = e.Message });

            }


        }
    }
}
